<html>
<head><meta charset="utf-8"><title>Extra hint for old-style `asm!` with AT&amp;T syntax? · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html">Extra hint for old-style `asm!` with AT&amp;T syntax?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="198721852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198721852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198721852">(May 26 2020 at 05:28)</a>:</h4>
<p>Consider a case like this:</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(asm)]</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;push %rax ; pop %rax&quot;</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="198721860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198721860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198721860">(May 26 2020 at 05:29)</a>:</h4>
<p>There aren't any outputs, inputs, clobbers, or options, so we can't tell at the syntax level that it's old-style <code>asm!</code> syntax.</p>



<a name="198721870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198721870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198721870">(May 26 2020 at 05:29)</a>:</h4>
<p>So, this gives an error from the assembler, like this:</p>
<div class="codehilite"><pre><span></span><code>error: &lt;inline asm&gt;:2:7: error: unknown token in expression
        push %rax ; pop %rax
             ^


error: &lt;inline asm&gt;:2:18: error: unknown token in expression
        push %rax ; pop %rax
                        ^
</code></pre></div>



<a name="198721996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198721996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198721996">(May 26 2020 at 05:32)</a>:</h4>
<p>Do we, at that point, have enough information in rustc that we could <em>theoretically</em> notice that we're in application-provided assembly, notice that the unknown token error points to a <code>%</code> symbol (likewise for other notable symbol differences between AT&amp;T and Intel), and iff all of those things are true, add a "help:" note that steers people towards the <code>asm!</code> syntax change and suggests <code>option(att_syntax)</code>?</p>



<a name="198728670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198728670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198728670">(May 26 2020 at 07:38)</a>:</h4>
<p>I think that would be extremely difficult to do reliably. Additionally I don't think it is such a big issue since operand-less <code>asm!</code> is very rarely used. Most of the time they at least have volatile or a memory clobber.</p>



<a name="198728735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198728735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198728735">(May 26 2020 at 07:38)</a>:</h4>
<p>By the way we already emit rustfix suggestions to use <code>llvm_asm!</code> if we detect use of the old style syntax with <code>:</code>.</p>



<a name="198749813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198749813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198749813">(May 26 2020 at 11:45)</a>:</h4>
<p>(Is there an open bug for the errors not giving a source file? That seems pretty annoying.)</p>



<a name="198771009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198771009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198771009">(May 26 2020 at 14:37)</a>:</h4>
<p>I'm working on it right now.</p>



<a name="198812439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198812439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198812439">(May 26 2020 at 19:48)</a>:</h4>
<p>See <a href="https://github.com/rust-lang/rust/issues/72625">#72625</a> for improved asm diagnostics.</p>



<a name="198829908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198829908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198829908">(May 26 2020 at 22:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F/near/198728735">said</a>:</p>
<blockquote>
<p>By the way we already emit rustfix suggestions to use <code>llvm_asm!</code> if we detect use of the old style syntax with <code>:</code>.</p>
</blockquote>
<p>I realized this; that's why I was asking about the case of no outputs, inputs, clobbers, or options, since then there'd be no <code>:</code>.</p>



<a name="198830055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198830055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198830055">(May 26 2020 at 22:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F/near/198728670">said</a>:</p>
<blockquote>
<p>I think that would be extremely difficult to do reliably. Additionally I don't think it is such a big issue since operand-less <code>asm!</code> is very rarely used. Most of the time they at least have volatile or a memory clobber.</p>
</blockquote>
<p>I don't think it needs to be ultra-reliable. I'm talking about a heuristic like "if the character is <code>$</code>, <code>%</code>, <code>(</code>, or a few other things, emit a hint that the asm syntax has changed".</p>



<a name="198830099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198830099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198830099">(May 26 2020 at 22:37)</a>:</h4>
<p>I'd even be open to "if the asm syntax has no arguments, so it's ambiguous whether it may be old-style or new style, and there's <em>any</em> syntax error in it, emit the hint".</p>



<a name="198830118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198830118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198830118">(May 26 2020 at 22:37)</a>:</h4>
<p>That's actually quite tricky because of how we process syntax errors from the assembler.</p>



<a name="198830168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198830168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198830168">(May 26 2020 at 22:38)</a>:</h4>
<p>By the time we get those we have lost almost all the syntax-level context associated with it.</p>



<a name="198830186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198830186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198830186">(May 26 2020 at 22:38)</a>:</h4>
<p>So we can't even know if that asm was originally from asm!, llvm_asm! or even global_asm!.</p>



<a name="198830570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198830570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198830570">(May 26 2020 at 22:43)</a>:</h4>
<p>That's unfortunate. It'd be really nice to be able to map them back up to the source file.</p>



<a name="198830582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198830582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198830582">(May 26 2020 at 22:43)</a>:</h4>
<p>Do we not have any way to tag them?</p>



<a name="198830666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Extra%20hint%20for%20old-style%20%60asm%21%60%20with%20AT%26T%20syntax%3F/near/198830666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Extra.20hint.20for.20old-style.20.60asm!.60.20with.20AT.26T.20syntax.3F.html#198830666">(May 26 2020 at 22:44)</a>:</h4>
<p>Ah, I just read <a href="https://github.com/rust-lang/rust/pull/72625">https://github.com/rust-lang/rust/pull/72625</a> about that.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>